﻿using System;
using System.Collections.Generic;
using System.Text;

namespace PalindromeLinkedList
{
    public class ListNode
    {
        public int val;
        public ListNode next;
        public ListNode(int x) { val = x; }
    }

    public class Solution
    {

        public bool IsPalindrome(ListNode head)
        {
            if (head == null)
                return true;

            List<int> list = new List<int>();

            while (head != null)
            {
                list.Add(head.val);
                head = head.next;
            }

            for (int i = 0, j = list.Count - 1; i < j; i++, j--)
            {
                if (list[i] != list[j])
                    return false;
            }

            return true;

        }

        public void PrintListNode(ListNode ln)
        {
            Console.Write("(");
            while (ln != null)
            {
                Console.Write(ln.val);

                if (ln.next != null) Console.Write("->");

                ln = ln.next;
            }

            Console.Write(")");
        }
    }
}